/**
 * @author Evgeny Sorokin
 */
Ext.define('USocial.store.AppUserStore', {
	extend : 'Ext.data.Store',
	
	requires : ['Ext.data.proxy.LocalStorage'],
	
	buildProxy : function(){
		this.setProxy({
			type : 'jsonp',
			url : 'https://api.vk.com/method/users.get?user_ids='
					+ USocial.app.getUserInfo().get('id')
					+ '&fields=nickname,city,country,sex,photo_100,photo_50&access_token='
					+ USocial.app.getUserInfo().get('token'),
			reader : {
				type : 'json',
				rootProperty : 'response'
			}
		});
	},
	
	config : {
		model : 'USocial.model.User',
		listeners : {
			addrecords :{
				scope : this,
				fn : function(store, records){
					if(store.getAllCount() > 1){
						store.remove(store.last());
						throw Error('AppUserStore must contain only current user data');
					}
				}
			}
		}
	}

});